package com.boot.web.controller;

import java.util.Date;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.boot.communal.paging.InitPaging;
import com.boot.communal.response.ResponseServer;
import com.boot.web.entity.StoreShop;
import com.boot.web.service.StoreShopService;

/**
 * 店铺控制器
 * @author 【zhouJie】
 * @date 2021-06-02 08:43:22
 */
@RestController
@RequestMapping("/storeShop")
public class StoreShopController {

    @Autowired
    private StoreShopService storeShopService;

    @PostMapping("/save")
    public ResponseServer save(StoreShop storeShop) {
        storeShop.setUpdateTime(new Date());
        return ResponseServer.success("添加成功", storeShopService.save(storeShop));
    }

    @PutMapping("/update")
    public ResponseServer update(StoreShop storeShop) {
        storeShop.setUpdateTime(new Date());
        return ResponseServer.success("修改成功", storeShopService.update(storeShop));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseServer delete(@PathVariable Integer id) {
        return ResponseServer.success("删除成功", storeShopService.delete(id));
    }

    @DeleteMapping("/batchDelete/{ids}")
    public ResponseServer batchDelete(@PathVariable Integer[] ids) {
        return ResponseServer.success("批量删除成功", storeShopService.batchDelete(ids));
    }

    @GetMapping("/getPageList")
    public ResponseServer getPageList(@RequestParam Map<String, Object> params) {
        InitPaging.init(params);
        return ResponseServer.success(new PageInfo(storeShopService.getPageList(params)));
    }

    @GetMapping("/getAll")
    public ResponseServer getAll() {
        return ResponseServer.success(storeShopService.getAll());
    }

    @GetMapping("/getById/{id}")
    public ResponseServer getById(@PathVariable Integer id) {
        return ResponseServer.success(storeShopService.getById(id));
    }

}
